package com.zb.jnlxc.dao;

import java.util.List;

import javax.annotation.Resource;

import com.zb.jnlxc.model.ProductProcess;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import com.ZLHW.base.dao.DAO;
import com.zb.jnlxc.model.LiaoKuang;
import com.zb.jnlxc.model.ProductDetail;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 14-8-16
 * Time: 下午4:00
 * To change this template use File | Settings | File Templates.
 */
@Component
public class LiaoKuangDAO extends DAO<LiaoKuang, Integer> {
    @Resource
    ProductProcessDAO        productProcessDAO;

    public LiaoKuang getBycode(String code) {
        List<LiaoKuang> list = getByColumn("code", code);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        } else {
            return null;
        }
    }

    /**
     * 获取料框理论重量
     * @param liaoKuangId
     * @return
     */
    public Integer getLiaoKuangWeight(Integer liaoKuangId) {
        List<ProductProcess> productProcesses = productProcessDAO.getByLiaoKuangId(liaoKuangId);
        int weight = 0;
        for (ProductProcess productProcess : productProcesses) {
            weight += productProcess.getRealWeight();
        }
        LiaoKuang liaoKuang = getById(liaoKuangId);
        weight +=liaoKuang.getWeight();
        return weight;
    }

}
